import sys
import os

pwd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(pwd)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
import django
django.setup()

from django.contrib.auth.models import User
from django.core.mail import send_mail
from blog.models import Post
from django.http import JsonResponse
from django.views.generic import TemplateView
from django.views.generic.detail import BaseDetailView,SingleObjectTemplateResponseMixin


from blog.models import Post
from blog.api.serializers import SubjectSerializer

subject = Post.objects.all()[0]
serializer = SubjectSerializer(subject)
print(serializer.data)

from io import BytesIO
from rest_framework.parsers import JSONParser

data = b'{"id":4,"title":"music","slug":"music"}'
JSONParser.parse(BytesIO(data))

#class JSONResponseMixin(object):


#	def render_to_json_response(self,context,**response_kwargs):
#		return JsonResponse(context,**response_kwargs)

#	def get_data(self,context):
#		return context 

#class JSONView(JSONResponseMixin,TemplateView):
#	def render_to_response(self,context,**response_kwargs):
#		return self.render_to_json_response(context,**response_kwargs)

#class JSONDetailView(JSONResponseMixin,BaseDetailView):
#	def render_to_response(self,context,**response_kwargs):
#		return self.render_to_json_response(context,**response_kwargs)

#class HybirdDetailView(JSONResponseMixin,SingleObjectTemplateResponseMixin,BaseDetailView):
#	def render_to_response(self,context):
#		if self.request.GET.get('format') == 'json':
#			return self.render_to_json_response(context)
#		else:
#			return super(HybirdDetailView,self).render_to_response(context)